package com.yxw.contentproviderdemo02;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.net.Uri;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ContentResolver cr=getContentResolver();
        //像联系人中插入一行数据
        ContentValues values= new ContentValues();
       Uri uri= cr.insert(ContactsContract.RawContacts.CONTENT_URI,values);

        Long raw_contact_id=ContentUris.parseId(uri);

        values.clear();
//插入人名
        values.put(ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID,raw_contact_id);
        values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,"张三三");
        values.put(ContactsContract.CommonDataKinds.StructuredName.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);

        uri=cr.insert(ContactsContract.Data.CONTENT_URI,values);


//插入电话信息
        values.clear();
        values.put(ContactsContract.CommonDataKinds.Phone.RAW_CONTACT_ID,raw_contact_id);
        values.put(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,"张三三");
        values.put(ContactsContract.CommonDataKinds.Phone.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);

        uri=cr.insert(ContactsContract.Data.CONTENT_URI,values);
    }
}
